(function(){
	Ccay.UI.Element = $.IFactory({
		setDefault:true,
		mapping:{
			tag:"div",
			render:function(dom){
				if(this.initElem){
					var op = this.loadProp(dom);
					this.initElem(dom,op);
				}
			},
			initElem:function(dom,op){
				var ctr = this.controlType ? dom[this.controlType] : null;
				if(ctr){
					return ctr.call(dom,op);
				}
			},
			loadOp:function(dom){
				var op = {},config;
				$.each(this.baseProp,function(i,prop){
					if(config = dom.attr(prop))
					{
						dom.removeAttr(prop);
						config[prop] = config;
					}
				})
				if(config = dom.attr("config"))
				{
					$.extend(true,op,Ccay.DataHelper.toJson(config));
				}
				
				return op;
			}
		}
	});
	
	//属性
	Ccay.UI.Element.Propertes = $.IFactory({
		type:"copy",
		setDefault:true,
		mapping:{
			dataType:null,
			parse:function(value){
				return value;
			}
		},
		proto:{
			
		}
	});
	
	//属性
	var Events = Ccay.UI.Element.Events = $.IFactory({
		setDefault:true,
		type:"copy",
		mapping:{
			bind:function(dom,eventOp){
				if(!this.delegate)
				{
					if(eventOp.target)
						dom.on(this.type,eventOp.target,eventOp.fn);
					else
						dom.on(this.type,eventOp.fn);
				}
			}
		},
		proto:{
//			events:{
//				clcik:["click","dbclick","hover"],
//				focus:["focus","blur","focusin","focusout"],
//				keyboard:["keydown","keypress","keyup"],
//				mouse:["mousedown","mouseenter","mouseleave","mousemove","mouseout","mouseover"]
//			},
			pushDelegate:function(delegate){
				if(typeof(delegate) == "string")
				{
					Events.add(delegate,{
						delegate:true
					});
				}
				else
				{
					$.each(delegate,function(i,type){
						Events.add(type,{
							delegate:true
						});
					})
				}
			},
			buildEvent:function(eventOp){
				if(eventOp && eventOp.fn)
				{
					var event = $.extend({},eventOp);
					try{
						event.fn = new Function(['e'],event.fn); 
					}
					catch(e){
						return null;
					}
					return event
				}
			},
			bind:function(dom,events){
				if(events)
				{
					var eventFn = {},self = this,event;
					$.each(events,function(eventName,eventOp){
						if(event = self.buildEvent(eventOp))
							self.get(eventName).bind(dom,event);
					})
					dom.data("ElemEvents",events);
				}
			}
		}
	});

})();